import random
import time

class expander:

    def  __init__(self):
        self.f,self.r,self.d = list(),list(),list()
        self.l_count, self.f_count,self.r_count,self.d_count = 0,0,0,0
        self.conflict = []
        self.deleted = set()
        self.max_cover = set()

    def read_sets(self,count,lst,inp):
        print count
        for i in xrange(count):
            s = inp.readline()
            z = [set(),set()]
            for c in xrange(len(s)):
                if s[c] == '0':
                    z[0].add(c)
                if s[c] == '1':
                    z[1].add(c)
            lst.append(z)

    def read_data(self):
        inp = open("input.txt","r")
        self.l_count, self.f_count,self.r_count,self.d_count= map(int,inp.readline().split(' '))
        self.read_sets(self.f_count, self.f,inp)
        self.read_sets(self.r_count, self.r,inp)
        self.read_sets(self.d_count, self.d,inp)
        inp.close()

    def make_conflict(self):
        for i in xrange(self.f_count):
            self.conflict.append([])
            for j in xrange(self.f_count):
                self.conflict[i].append(set())
                for l in xrange(self.l_count):
                    if l in self.f[i][0] and l in self.f[j][0]:
                        self.conflict[i][j].add(l)
                    if l in self.f[i][1] and l in self.f[j][1]:
                        self.conflict[i][j].add(l)
                    if not( l in self.f[i][0] or l in self.f[i][1]):
                        self.conflict[i][j].add(l)


    def make_cover(self,cover,block,deep,num):
        if deep < self.r_count:
            if len(cover.intersection(block[deep])) > 0:
                self.make_cover(cover, block, deep+1,num)
            else:
                for e in block[deep]:
                    cover.add(e)
                    self.make_cover(cover, block, deep+1,num)
                    cover.remove(e)
        else:
            ans = 0
            for  i in xrange(self.f_count):
                if not i in self.deleted:
                    if self.conflict[num][i].issuperset(cover):
                        ans +=1
            if ans > len(self.max_cover):
                self.max_cover.clear()
                self.max_cover.update(cover)

    def expand(self):
        for i in xrange(self.f_count):
            if i not in self.deleted:
                b = []
                for j in xrange(self.r_count):
                    b.append(set())
                    for l in xrange(self.l_count):
                        if (l in self.f[i][0] and l in self.r[j][1]) or (l in self.f[i][1] and l in self.r[j][0]):
                            b[j].add(l)
                self.max_cover.clear()
                self.make_cover(set(),b,0,i)
                for  j in xrange(self.f_count):
                    if not i==j and self.max_cover.issubset(self.conflict[i][j]):
                        self.deleted.add(j)
                self.f[i][0].intersection_update(self.max_cover)
                self.f[i][1].intersection_update(self.max_cover)

    def write_results(self):
        outp = open("output.txt","w")
        for i in xrange(self.f_count):
            if not i in self.deleted:
                for j in xrange(self.l_count):
                    if j in self.f[i][0]:
                        outp.write("0")
                    elif j in self.f[i][1]:
                        outp.write("1")
                    else:
                        outp.write("2")
                outp.write("\n")
        outp.close()

    def do_all(self):
        self.read_data()
        self. make_conflict()
        self.expand()
        self.write_results()

def create_tests(var,cube):
    base_f = []
    base_r = []
    for i in xrange(2**(var/3)):
        s = bin(i)[2:]
        s +="2"*(var-len(s))
        if random.randint(0,1) == 0:
            base_f.append(s)
        else:
            base_r.append(s)
    f = []
    r = []
    for i in xrange(cube):
        if random.randint(0,1) == 0 and len(base_f) > 0:
            s = list(random.choice(base_f))
            for j in xrange(var):
                if s[j] == '2':
                    xx = random.randint(0,3)
                    if xx == 0:
                        s[j] = '1'
                    elif xx==1:
                        s[j] = '0'
            f.append("".join(s))
        elif len(base_r) > 0:
            s = list(random.choice(base_r))
            for j in xrange(var):
                if s[j] == '2':
                    xx = random.randint(0,3)
                    if xx == 0:
                        s[j] = '1'
                    elif xx==1:
                        s[j] = '0'
            r.append("".join(s))
    outp = open("input.txt","w")
    outp.write(" ".join(map(str,[var,len(f),len(r),0]))+'\n')
    outp.write("\n".join(f)+'\n')
    outp.write("\n".join(r)+'\n')
    outp.close()

results = []
var_nums = [i*2+1 for i in xrange(1,10)]
cube_nums = [2**i for i in xrange(2,12)]

with open("results.txt","w") as outp:
    for i in var_nums:
        res = []
        for j in cube_nums:
            if 2**(i-1)>=j:
                create_tests(i,j)
                x = time.time()
                a = expander()
                a.do_all()
                res.append(time.time()-x)
            else:
                res.append(0)
        outp.writelines(" ".join(map(str,res))+'\n')
        outp.flush()

